/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aic.beans;

import java.math.BigDecimal;
import java.util.UUID;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Item {

    private int quantity;
    private String product_id;
    private BigDecimal single_unit_price;

    public Item() {
        UUID uuid = UUID.randomUUID();
        this.product_id = uuid.toString();
    }

    public Item(int quantity, String product_id, double single_unit_price) {
        this.quantity = quantity;
        this.product_id = product_id;
        this.single_unit_price = new BigDecimal(single_unit_price);
    }

    @XmlElement
    public String getProduct_id() {
        return product_id;
    }

    public void setProduct_id(String product_id) {
        this.product_id = product_id;
    }

    @XmlElement
    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    @XmlElement
    public BigDecimal getSingle_unit_price() {
        double tmp = Math.round(single_unit_price.doubleValue()*100);
        BigDecimal tmp2 = new BigDecimal(tmp);
        return tmp2.divide(new BigDecimal(100));
    }

    public void setSingle_unit_price(BigDecimal single_unit_price) {
        this.single_unit_price = single_unit_price;
    }

    @Override
    public String toString() {
        return "product_id: " + this.product_id + " / single_unit_price: " + getSingle_unit_price() + " / quantity: " + this.quantity;
    }

    @Override
    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
    public boolean equals(Object obj) {

        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final Item other = (Item) obj;
        if (!this.getProduct_id().equals(other.getProduct_id())) {
            return false;
        }
        if (!this.getSingle_unit_price().equals(other.getSingle_unit_price())) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (this.product_id != null ? this.product_id.hashCode() : 0);
        hash = 41 * hash + (this.single_unit_price != null ? this.single_unit_price.hashCode() : 0);
        return hash;
    }
}
